package com.keson.blue;

import android.Manifest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;

import com.keson.blue.R;

import java.lang.reflect.Method;

public class MainActivity extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        checkBTPermission();
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        finish();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //取消广播接收者的注册
    }

    private void checkBTPermission() {
        Log.d("TAG", "checkBTPermission: Start");
        if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP){
            int permissionCheck = 0;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                permissionCheck = this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
                permissionCheck += this.checkSelfPermission("Manifest.permission.ACCESS_COARSE_LOCATION");
                permissionCheck += this.checkSelfPermission("Manifest.permission.BLUETOOTH_PRIVILEGED");
                if(permissionCheck != 0){
                    System.out.println("BLUETOOTH_PRIVILEGED");
                    this.requestPermissions(new String[]{
                            Manifest.permission.ACCESS_FINE_LOCATION,
                            Manifest.permission.ACCESS_COARSE_LOCATION,
                            Manifest.permission.BLUETOOTH_PRIVILEGED,
                            Manifest.permission.ACCESS_WIFI_STATE,
                            Manifest.permission.CHANGE_WIFI_STATE
                    }, 1001); //any number
                }else{
                    Log.d("TAG",
                            "checkBTPermissions: No need to check permissions. SDK version < LOLLIPOP.");
                }
            }

        }
        Log.d("TAG", "checkBTPermission: Finish");
    }
}